<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <i class="el-icon-lx-cascades"></i> 面试管理
                </el-breadcrumb-item>    
                <el-breadcrumb-item>修改面试信息</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <el-table
                :data="tableData"
                border
                class="table"
                header-cell-class-name="table-header"
            >
                <el-table-column prop="interId" label="面试记录id"></el-table-column>
                <el-table-column prop="hrId" label="人力资源id"></el-table-column>
                <el-table-column prop="canId" label="应聘者id"></el-table-column>
                <el-table-column prop="interDetail" label="hr评价"></el-table-column>
                <!-- <el-table-column label="头像(查看大图)" align="center">
                    <template #default="scope">
                        <el-image
                            class="table-td-thumb"
                            :src="scope.row.thumb"
                            :preview-src-list="[scope.row.thumb]"
                        ></el-image>
                    </template>
                </el-table-column> -->
                <!-- <el-table-column prop="canExperience" label="工作经验"></el-table-column> -->
                <!-- <el-table-column label="面试状态" align="center">
                    <template #default="scope">
                        <el-tag
                            :type="
                                scope.row.state === '成功'
                                    ? 'success'
                                    : scope.row.state === '失败'
                                    ? 'danger'
                                    : ''
                            "
                        >{{ scope.row.state }}</el-tag>
                    </template>
                </el-table-column> -->
                <!-- <el-table-column prop="canWantPosition" label="期望职位"></el-table-column> -->
                <el-table-column label="操作" width="180" align="center">
                    <template #default="scope">
                        <el-button
                            type="text"
                            icon="el-icon-edit"
                            @click="handleEdit1(scope.$index, scope.row)"
                        >简历</el-button>
                        <!-- <el-button
                            type="text"
                            icon="el-icon-edit"
                            @click="handleEdit2(scope.$index, scope.row)"
                        >编辑</el-button> -->
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination">
                 <el-pagination
                    @current-change="getData"
                    :current-page="currentPage"
                    :page-count="totalPage"
                    layout="prev, pager, next"
                    background
                    hide-on-single-page
                ></el-pagination>
            </div>
        </div>
        
        <!-- 简历弹出框 -->
        <el-dialog title="简历" v-show="editVisible1" width="30%">
                <el-form-item label="应聘者Id">
                    <el-input v-model="form.canId"></el-input>
                    </el-form-item>
                <el-form-item label="人力资源Id">
                    <el-input v-model="form.hrId"></el-input>
                    </el-form-item>
                <el-form-item label="面试记录id">
                    <el-input v-model="form.interId"></el-input>
                    </el-form-item>
                <el-form-item label="hr评价">
                    <el-input type="textarea" :rows="2" v-model="form.interDetail"></el-input>
                    </el-form-item>
            <template #footer>
                <span class="dialog-footer">
                    <el-button @click="editVisible1 = false">取 消</el-button>
                    <el-button type="primary" @click="saveEdit1">确 定</el-button>
                </span>
            </template>
        </el-dialog>

        <!-- 编辑弹出框 -->
        <el-dialog title="编辑" v-show="editVisible2" width="30%">
            <el-form ref="form" :model="form" label-width="70px">
                <el-form-item label="面试记录id">
                    <el-input v-model="form.interId"></el-input>
                </el-form-item>
                <el-form-item label="人力支援id">
                    <el-input v-model="form.hrId"></el-input>
                </el-form-item>
                <el-form-item label="应聘者id">
                    <el-input v-model="form.canId"></el-input>
                </el-form-item>
                <el-form-item label="hr评价">
                    <el-input v-model="form.interDetail"></el-input>
                </el-form-item>
            </el-form>
            <template #footer>
                <span class="dialog-footer">
                    <el-button @click="editVisible2 = false">取 消</el-button>
                    <el-button type="primary" @click="saveEdit2">确 定</el-button>
                </span>
            </template>
        </el-dialog>
    </div>
</template>

<script>
export default {
    name: "modifyi",
    data() {
        return {
            query:{
                ID:'',
                power:''
            },
            position:"",
            tableData: [],
            multipleSelection: [],
            delList: [],
            editVisible1: false,
            editVisible2: false,
            totalPage: 0,
            idx:'',
            form: {},
            currentPage:0,
            cDetailList:[]
        };
    }
    ,
    mounted() {
        this.getData(1);
    },
    methods: {
        
        // 获取 easy-mock 的模拟数据
        getData(currentPage) {
            const _this = this;
            _this.getBlogData(currentPage);
        },
        getBlogData(currentPage) {
            const _this = this;
            console.log(currentPage)
             this.$axios
                .get('/Interview/getAllInterview',
                {
                    params:{
                        currentPage:parseInt(currentPage)
                    },
                    headers: {
                        Authorization: localStorage.getItem('token')
                    }
                })
                .then(res => {
                    if (res.data.code == 200) {
                        console.log(res)
                        this.tableData = res.data.data.data;
                        this.totalPage = res.data.data.totalPage;
                        this.currentPage = res.data.data.currentPage;
                    } else {
                        this.$message.error("获取名单失败！");
                    }
                });
        },
        // const _this = this;
        //     this.$axios.get('/queryFriend/' + _this.query.link_name).then(res => {
        //         if (res.data.code == 200) {
        //             this.$message.success(res.data.msg);
        //             _this.friendList = res.data.data;
        //         } else {
        //             this.$message.error(res.data.msg);
        //         }
        //     });
        // 获取应聘者详情信息
        getDetail1()
        {
            const _this = this;
             this.$axios
                .get('/Interview/getInterviewByCanId/'+_this.query.ID,)
                .then(res => {
                    if (res.data.code == 200) {
                        console.log( res)
                        _this.cDetailList = res.data.data;
                    } else {
                        this.$message.error("搜索失败！");
                    }
                });
        },
        // 根据power获取应聘者详情信息
        getDetail2()
        {
            const _this = this;
             this.$axios
                .get('/Candidate/getCandidatesByPower/'+_this.query.power,)
                .then(res => {
                    if (res.data.code == 200) {
                        console.log( res)
                        _this.cDetailList = res.data.data;
                    } else {
                        this.$message.error("搜索失败！");
                    }
                });
        },
        // 触发搜索按钮1
        handleSearch1() {
            this.$set(this.query, "pageIndex", 1);
            this.getDetail1();
        },
        // 触发搜索按钮2
        handleSearch2() {
            this.$set(this.query, "pageIndex", 1);
            this.getDetail2();
        },
        // 多选操作
        handleSelectionChange(val) {
            this.multipleSelection = val;
        },
        // 编辑操作
        handleEdit1(index, row) {
            this.idx = index;
            this.form = row;
            this.editVisible1 = true;
        },
        handleEdit2(index, row) {
            this.idx = index;
            this.form = row;
            this.editVisible2 = true;
        },
        // 保存编辑
        saveEdit1() {
            this.editVisible1 = false;
            this.$message.success(`修改第 ${this.idx + 1} 行成功`);
            this.$set(this.tableData, this.idx, this.form);
        },
        // 保存编辑
        saveEdit2() {
            this.editVisible2 = false;
            this.$message.success(`修改第 ${this.idx + 1} 行成功`);
            this.$set(this.tableData, this.idx, this.form);
        },
        // 分页导航
        handlePageChange(val) {
            this.$set(this.query, "pageIndex", val);
            this.currentPage = val;
            this.getData();
        }
    }
};
</script>

<style scoped>
.handle-box {
    margin-bottom: 20px;
}

.handle-select {
    width: 120px;
}

.handle-input {
    width: 300px;
    display: inline-block;
}
.table {
    width: 100%;
    font-size: 14px;
}
.red {
    color: #ff0000;
}
.mr10 {
    margin-right: 10px;
}
.table-td-thumb {
    display: block;
    margin: auto;
    width: 40px;
    height: 40px;
}
</style>
